const path = require('path')
const resolve = function (filepath) {
  return path.resolve(__dirname, filepath)
}

const NODE_ENV = process.env.NODE_ENV || 'development'
const isProd = ['production', 'prod'].some(x => NODE_ENV === x)
const envName = isProd ? 'production' : NODE_ENV

module.exports = {
  /**
   * Application configuration section
   * http://pm2.keymetrics.io/docs/usage/application-declaration/
   */
  apps : [
    {
      "name"            : `richard:auth_service:${envName}`,
      "script"          : `./pms_rest_server/${isProd ? 'prod' : 'dev'}.sh`,
      "exec_mode"        : "fork",
      "cwd"               : resolve("./pms_rest_server"),
      "error_file"        : resolve(`./data/log/${envName}/pms_rest_server.error.log`),
      "out_file"           : resolve(`./data/log/${envName}/pms_rest_server.out.log`),
      "exec_interpreter" : "bash",
      "instances"       : 1,
      "env": {
        PORT: 7001
      },
      "env_production": {}
    },
    // {
    //   "name"            : `richard:client:admin:${envName}`,
    //   "script"          : `./client_web_admin/${isProd ? 'build' : 'dev'}.sh`,
    //   "exec_mode"        : "fork",
    //   "cwd"               : resolve("./client_web_admin/"),
    //   "error_file"        : resolve(`./data/log/${envName}/client_web_admin.error.log`),
    //   "out_file"           : resolve(`./data/log/${envName}/client_web_admin.out.log`),
    //   "exec_interpreter" : "bash",
    //   "instances"       : 1,
    //   "env": {},
    //   "env_production": {}
    // }
  ],

  /**
   * Deployment section
   * http://pm2.keymetrics.io/docs/usage/deployment/
   */
  deploy : {
  }
};
